package com.abbas.smartCity.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
import com.abbas.smartCity.util.NetScope
import com.abbas.smartCity.util.NoImpl
import java.lang.reflect.ParameterizedType

@NoImpl
abstract class BaseBindingFragment<VB: ViewBinding> : Fragment(), NetScope {

    protected lateinit var binding: VB

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        var parameterizedType = javaClass.genericSuperclass as ParameterizedType
        var clazz = parameterizedType.actualTypeArguments[0] as Class<*>
        var declaredMethod = clazz.getDeclaredMethod("inflate", LayoutInflater::class.java,ViewGroup::class.java,Boolean::class.java)
        binding = declaredMethod.invoke(null, layoutInflater,container,false) as VB

        initData()
        initEvent()

        return binding.root
    }

    /**
     * 数据操作、网络操作
     */
    protected abstract fun initData()

    /**
     * 监听设置、事件设置
     */
    protected abstract fun initEvent()
}